package com.yc.project.dao;

import com.yc.common.util.DBHelper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SearchDao {
    public Map<String,Object> selectdish (String context,String page) {
        String sql = "select * from gghc_dish d left join gghc_kind g on d.sort=g.id " ;
        List<Object> params = new ArrayList<>();
        if( context !=null && context.trim().isEmpty() == false) {
            sql += " where name like ? or tag1 like ? or " +
                    " tag2 like ? or " +
                    " tag3 like ? or " +
                    " kname like ? ";
            params.add("%" + context + "%");
            params.add("%" + context + "%");
            params.add("%" + context + "%");
            params.add("%" + context + "%");
            params.add("%" + context + "%");
        }

        //查询总行数
        long count = DBHelper.count(sql, params.toArray());
        int ipage = Integer.parseInt(page);
        ipage = (ipage - 1) * 10;
        sql += " limit " + ipage + ",10";
        List<Map<String, Object>> list = DBHelper.selectListMap(sql, params.toArray());

        Map<String, Object> ret = new HashMap<>();
        ret.put("total",count);
        ret.put("data",list);

        return ret;
    }
}
